package com.atlin.project.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

@Configuration
public class JacksonConfig {

    @Bean
    @Primary
    public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
        return builder -> {
            builder.serializers(new ToStringSerializer(java.util.UUID.class));
            builder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
            builder.timeZone("GMT+8");
            builder.modulesToInstall(new JavaTimeModule());
            // 可以添加其他配置
        };
    }

    // 如果你需要直接访问定制后的ObjectMapper，也可以提供一个Bean
    @Bean
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.build();
        // 这里你可以添加额外的配置到ObjectMapper，如果需要的话
        return objectMapper;
    }
}